package com.reger.l2cache.bloomfilter.hash;

import com.reger.l2cache.bloomfilter.Hash;

public class RsHash implements Hash {

	private final long cap;

	public RsHash(long cap) {
		super();
		this.cap = cap;
	}

	@Override
	public long hash(String data) {
		int b = 378551;
		int a = 63689;
		long hash = 0;
		for (int i = 0; i < data.length(); i++) {
			hash = hash * a + data.charAt(i);
			a = a * b;
		}
		return (hash & (cap - 1));
	}

}
